<?php

class Supplier
{    
    var $ID;
    var $supplier =  ''; 
    var $code = '';
	
    public function retrieve() 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT * from tblsupplier");
	return $result;        
    }
    
     public function retrieveByName($searchVal) 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT * from tblsupplier WHERE Supplier LIKE '%$searchVal%'");
	return $result;        
    }
    
    public function retrieveByCode($code) 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT * from tblsupplier WHERE Code='$code'");
	$row = mysql_fetch_array($result);
	$this->supplier =  $row['Supplier'];
	$this->code =  $row['Code'];
    }
    
    public function add()
    {       
      	 require('../includes/DBConn.inc');
      	 $query = "INSERT INTO tblsupplier (code,supplier) VALUES ('$_POST[code]','$_POST[name]')";
      	      
      	 $result = mysql_query($query) or die("Error: ".mysql_error());
      	 return $result;
    }
    
    public function update($code)
    {
      	 require('../includes/DBConn.inc');
      	 $query = "UPDATE tblsupplier SET supplier='$_POST[name]' WHERE code='$code'";
      	 	   
      	 $result = mysql_query($query) or die("Error: ".mysql_error());
      	 return $result;
    }
    
    public function delete($code)
    {
    	 require('../includes/DBConn.inc');
         $result = mysql_query("DELETE FROM tblsupplier WHERE code='$code'") or die(mysql_error());   
    }
    
}
?>
